defmodule IocpMonitor.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  def start(_type, _args) do
    # List all child processes to be supervised
    children = [
      %{
        id: IocpMonitor.HTTPServer,
        start: {IocpMonitor.HTTPServer, :start_link, [nil, [port: Application.get_env(:iocp_monitor, :http_port)]]}
      },
      {Registry, [keys: :unique, name: IocpMonitor.DeviceAddressHolders]},
      {Registry, [keys: :unique, name: IocpMonitor.DataBuffers]},
      IocpMonitor.Repo,
      {IocpMonitor.Dumper.Supervisor, Application.get_env(:iocp_monitor, :dumper_workers)},
      {IocpMonitor.Client.Supervisor, nil},
      {IocpMonitor.Server.Supervisor, Application.get_env(:iocp_monitor, :port)}
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :rest_for_one, name: IocpMonitor.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
